package leetcode.code198;

public class Solution3 {

	public static void main(String[] args) {
		int[] nums = { 1, 3, 1 };
		int[] nums1 = { 2, 7, 9, 3, 1 };
		int[] nums2 = { 2, 1, 4, 5, 3, 1, 1, 3 };
		Solution3 solution = new Solution3();
		int result = solution.massage(nums2);
		System.out.println(result);
	}

	public int massage(int[] nums) {
		if (nums.length == 0) {
			return 0;
		}
		int dp[][] = new int[nums.length][2];
		dp[0][0] = nums[0];
		dp[0][1] = 0;
		for (int i = 1; i < nums.length; i++) {
			dp[i][0] = dp[i - 1][1] + nums[i];// 上次没接，这次接
			dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][1]);// 上次接了或者没接，这次不接
		}
		return Math.max(dp[nums.length - 1][0], dp[nums.length - 1][1]);
	}

}
